﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

namespace Fotobanka
{
    public partial class EditaceUzivatelu : System.Web.UI.Page
    {
        UserManager um;
        LoginInfo li;
        protected void Page_Load(object sender, EventArgs e)
        {
            um = new UserManager();
            li = (LoginInfo)Session["logged_user_id"];
        }

        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            if (e.NewValues["Email"] == null)
            {
                e.Cancel = true;
                errors.Text = "Uživatel musí mít email";

            } 
            else if (e.NewValues["FirstName"] == null || e.NewValues["LastName"] == null) {
                e.Cancel = true;
                errors.Text = "Uživatel musí mít jméno a příjmení";
            }
            else if (um.EmailAlreadyExist(e.NewValues["Email"].ToString(), Convert.ToInt32(e.OldValues["Id"].ToString())))
            {
                e.Cancel = true;
                errors.Text = "Uživatel s tímto emailem již existuje";
            }
            else
                errors.Text = "";
        }
    }
}
